/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dds2.serviceSystem.Dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.its.dds2.ServicesSystem.Modelo.Profile;

/**
 *
 * @author Carlos Asis
 */
@Stateless
public class ProfileDao extends AbstractFacade<Profile> implements ProfileDaoLocal {

    @PersistenceContext(unitName = "servicesSystem-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ProfileDao() {
        super(Profile.class);
    }

    @Override
    public Boolean FindDuplecity(Profile profile) {
        Query q = em.createNamedQuery("Profile.findByName");
        q.setParameter("name", profile.getName());
        return !q.getResultList().isEmpty();

    }
    
    @Override
    public Profile FindById(int id) {
        Query q = em.createNamedQuery("Profile.findById");
        q.setParameter("id", id);
        return (Profile)q.getResultList().get(0);

    }
}
